<template>
  <div>

    <van-nav-bar
      title="会员登录"
      left-arrow
    />

    <van-cell-group>
      <van-cell title="手机号登录" size="large" label="未注册的手机号登陆后将自动注册" />
    </van-cell-group>

    <van-form @submit="onSubmit">
      <van-field
        v-model="mobile"
        name="mobile"
        label="手机号"
        placeholder="手机号"
        :rules="[
        { required: true, message: '请填写手机号' },
        {pattern:/^(?:(?:\+|00)86)?1\d{10}$/,message:'1开头11位手机号'}
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[
        { required: true, message: '请填写密码' },
        { pattern: /^\w{6,}$/, message: '密码至少包含6个字符' }
        ]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>

  </div>
</template>

<script>
import { setToken } from '@/utils/local'
import router from '@/router'
import { login } from '@/api/user'
export default {
  name: 'LoginView',
  data () {
    return {
      mobile: '',
      password: '',
      isParty: false,
      partyData: {},
      smsCode: '246810'
    }
  },
  methods: {
    async onSubmit (values) {
      console.log(values)
      const res = await login({
        isParty: this.isParty,
        mobile: this.mobile,
        partyData: this.partyData,
        smsCode: this.smsCode
      })
      console.log(res)
      setToken(res.data.token)
      router.push('/')
      this.$toast.success('登录成功')
    }
  }
}
</script>

<style>

</style>
